package com.kgc.excpt;

import com.kgc.util.ResultBuildUtil;
import com.kgc.util.ReturnResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created on 2021/6/21.
 * Author: lzy
 * Description: 定义异常统一处理类
 */
@ControllerAdvice
@Slf4j
public class SysExceptionHandler {


    @ResponseBody
    @ExceptionHandler(SysException.class)
    public ReturnResult<String> handSysException(SysException ee){

        log.error("----- 获取系统抛出的自定义异常，异常码：{}，异常信息：{}",ee.getSysExceptionEnum().getExcptCode(),ee.getSysExceptionEnum().getExcptMsg());

        return ResultBuildUtil.fail(ee.getSysExceptionEnum().getExcptCode(),ee.getSysExceptionEnum().getExcptMsg());
    }



}
